#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
typedef vector<int> vector1;
typedef vector<vector<int>> vector2;
int check(vector1 a, vector1 b, vector1 e){
vector1 point;
for(int ee: e){
if(find(point.begin(), point.end(), a[ee-1])==point.end()){
point.push_back(a[ee-1]);
} else return 0;
if(find(point.begin(), point.end(), b[ee-1])==point.end()){
point.push_back(b[ee-1]);
} else return 0;
}
return 1;
}
void find(const vector1& a, const vector1& b, const int& k, vector1 e, const vector1& end, vector2& process, vector2& answer, int& crt){
for(int ee: e) std::cout<<ee<<" ";
cout<<endl;
if(crt) return;
if(e.size()<k-2) return;
if(!check(a, b, e)){
process.pop_back();
return;
}
cout<<"Check1"<<endl;
if(end.size()==e.size()){
int state=0;
for(int i=0; i<e.size(); ++i){
if(e[i]!=end[i]) state=1;
}
if(!state){
answer.assign(process.size(), vector1(process[0].size()));
copy(process.begin(), process.end(), answer.begin());
crt=1;
}
}
int ll_size=e.size();
for(int i=0; i<ll_size ; ++i){
if(!(find(e.begin(), e.end(), i+1)==e.end())) continue;
for(int j=0; j<e.size(); ++j){
vector1 e_tmp(e.size());
copy(e.begin(), e.end(), e_tmp.begin());
e_tmp.erase(e_tmp.begin()+j);
vector1 pusher={0, j+1};
process.push_back(pusher);
find(a, b, k, e_tmp, end, process, answer, crt);
}
cout<<"check2"<<endl;
vector1 e_tmp(e.size());
copy(e.begin(), e.end(), e_tmp.begin());
e_tmp.push_back(i+1);
vector1 pusher={1, i+1};
process.push_back(pusher);
find(a, b, k, e_tmp, end, process, answer, crt);
}
}
vector2 solution(int n, int m, vector1 a, vector1 b, int k, int m1, int m2, vector1 e1, vector1 e2){
vector2 answer, process;
int crt=0;
find(a, b, k, e1, e2, process, answer, crt);
return answer;
}
int main(void){
int n=5, m=6, k=2, m1=2, m2=2;
vector1 a={1, 1, 2, 2, 3, 4};
vector1 b={2, 3, 3, 4, 5, 5};
assert(a.size()==b.size() && a.size()==m);
vector1 e1={3, 6}, e2={2, 4};
assert(e1.size()==m1 && e2.size()==m2);
vector2 answer=solution(n, m, a, b, k, m1, m2, e1, e2);
if(answer.size()!=0){
cout<<"[";
for(int i=0; i<answer.size()-1; ++i){
cout<<"["<<answer[i][0]<<", "<<answer[i][1]<<"], ";
}
cout<<"["<<answer[answer.size()-1][0]<<", "<<answer[answer.size()-1][1]<<"]]"<<endl;
}
return 0;
}